/**
 * @description 交易对手基础信息
 * @author chenyan
 */

import { connect } from 'dva';
import React, { PropTypes, PureComponent } from 'react';
import ModalInst from '../../counterpartyManagement/creditLineManagement/creditSetting/Modal';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Row, Col, Card, Spin, Calendar, Badge, Empty, Tooltip, Button, Tabs, Modal, Select, message, Pagination } from 'antd';
import { PrimaryC, SecondHeaderC } from '../../../comps';
class CreditSettingDetailC extends PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      businessKey: undefined,
      timeStamp: undefined,
      detailData: {},
    };
  }

  componentDidMount() {
    //交易对手短名下拉列表
    this.props.dispatch({
      type: 'creditSettingM/getShortName',
      payload: {},
    });
  }

  UNSAFE_componentWillReceiveProps(nextProps) {
    if (this.state.timeStamp !== nextProps.timeStamp) {
      this.setState(
        {
          businessKey: nextProps.businessKey,
          timeStamp: nextProps.timeStamp,
        },
        () => {
          this.queryDetail();
        },
      );
    }
  }
  //查询授信设置详情
  queryDetail = () => {
    this.props.dispatch({
      //查询详情数据
      type: 'creditSettingM/getCreditDetail',
      payload: {
        id: this.state.businessKey,
        type: 'approval',
      },
      callback: (data) => {
        this.setState({
          detailData: data || {},
        });
      },
    });
  };

  render() {
    const { loading } = this.props;
    return (
      <Spin spinning={loading.effects['creditSettingM/getCreditDetail'] == true}>
        <SecondHeaderC title={'设置详情'} />
        <ModalInst type={'query'} detailData={this.state.detailData} id={this.state.businessKey} />
      </Spin>
    );
  }
}

export default connect(({ creditSettingM, loading }) => ({ creditSettingM, loading }))(CreditSettingDetailC);
